#include "Lines.h"

struct Vertex {
	FLOAT x, y, z, rhw;
	DWORD color;
	static CONST DWORD FVF = D3DFVF_XYZRHW | D3DFVF_DIFFUSE;
};


Lines::Lines() {

}

Lines::~Lines()
{
}

VOID Lines::Initialize(Graphic& gfx) {

	DWORD color = D3DCOLOR_XRGB(255, 255, 255);

	Vertex data[] = {
		 { 420.0f, 150.0f, 0.5f, 1.0f, color, },
		 { 420.0f, 350.0f, 0.5f, 1.0f, color, },
		 { 220.0f, 150.0f, 0.5f, 1.0f, color, },
		 { 220.0f, 350.0f, 0.5f, 1.0f, color, },
	};

	HRESULT hresult;
	hresult = gfx.Device()->CreateVertexBuffer(
		sizeof(data),
		0,
		Vertex::FVF,
		D3DPOOL_DEFAULT,
		&_VertexBuffer,
		nullptr
	);
	if (FAILED(hresult)) {
		return;
	}
	void* ptr;

	if (FAILED(_VertexBuffer->Lock(0, sizeof(data), (void**)&ptr, 0)))
		return;

	memcpy(ptr, data, sizeof(data));

	_VertexBuffer->Unlock();
}

VOID Lines::Draw(Graphic& gfx) {
	gfx.Device()->SetStreamSource(0, _VertexBuffer.Get(), 0, sizeof(Vertex));
	gfx.Device()->SetFVF(Vertex::FVF);
	gfx.Device()->DrawPrimitive(D3DPT_LINELIST, 0, 2);
}
